package com.suredy.app.indexcontent.ctrl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.suredy.tools.SuredyTreeModel;

/**
 * 公告controller
 * 
 * @author VIVID.G
 * @since 2015-4-9
 * @version v0.1
 */
@Controller
@RequestMapping("index_content")
public class IndexContent {

	/**
	 * get the content for index page.
	 * 
	 * @return
	 */
	@RequestMapping
	public ModelAndView getIndexContent() {
		ModelAndView view = new ModelAndView("appindexcontent/content");

		return view;
	}

	/**
	 * get the content for index page.
	 * 
	 * @return
	 */
	// TODO: for test
	@RequestMapping("test-tree")
	@ResponseBody
	public Object testTree() {
		List<SuredyTreeModel> tree = new ArrayList<SuredyTreeModel>();

		SuredyTreeModel t = new SuredyTreeModel();
		t.setText("node1");
		t.setCollapse(false);
		t.setChildren(new ArrayList<SuredyTreeModel>());

		SuredyTreeModel c1 = new SuredyTreeModel();
		c1.setText("node2");
		t.getChildren().add(c1);

		c1 = new SuredyTreeModel();
		c1.setText("node3");
		c1.setChildren(new ArrayList<SuredyTreeModel>());
		t.getChildren().add(c1);

		SuredyTreeModel c2 = new SuredyTreeModel();
		c2.setText("node4");
		c1.getChildren().add(c2);

		c2 = new SuredyTreeModel();
		c2.setText("node5");
		c1.getChildren().add(c2);

		tree.add(t);

		t = new SuredyTreeModel();
		t.setText("这里是一个很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长的节点");
		t.setCollapse(false);
		t.setLeaf(false);
		tree.add(t);

		t = new SuredyTreeModel();
		t.setText("这里是一个节点");
		t.setCollapse(false);
		tree.add(t);

		return tree;
	}

}
